package br.uneb.tebd.webservice;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import br.uneb.tebd.R;

public class FindByDescriptionWS extends Activity{
	private Button searchButton;
	private TextView description;
	private EditText text;
	private WebServiceClient client;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.webservice_find);
		
		this.client = new WebServiceClient();
		
		this.searchButton = (Button) findViewById(R.id.searchButtonWeb);

		this.text = (EditText) findViewById(R.id.textWeb);
		
		this.description = (TextView) findViewById(R.id.descriptionSearchWeb);
		
		this.searchButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				try {
					client.setDescription(description.getText().toString());
					client.setMethod(WebServiceClient.FIND_BY_DESCRIPTION);
				    client.Execute();
				} catch (Exception e) {
				    e.printStackTrace();
				}
				String value = client.getResponse();
				text.setText(value);
			}
		});
	}
}
